﻿/*
 * Created by SharpDevelop.
 * User: ratul
 * Date: 3/6/2010
 * Time: 12:09 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections;
using System.Collections.Generic;

namespace H264Impl.NET.Coding
{
	/// <summary>
	/// Description of CAVLC.
	/// </summary>
	public static class CAVLC
	{
		
		public static UInt32[] getCoeffLevelList(BitStream bitstream, Int32 maxNumCoeff, UInt32 blockIndex)
		{
//			List<UInt32> coeffLevelList = new List<UInt32>(maxNumCoeff);
//			foreach (UInt32 coeffLevel in coeffLevelList)
//                 coeffLevel = 0;

			UInt32[] coeffLevelList = new UInt32[maxNumCoeff];
			
			UInt32 totalCoeff; //= getTotalCoeff(bitstream, maxNumCoeff, blockIndex);
			UInt32 trailingOnes; //= getTrailingOnes();
			getCoeffToken(bitstream, nC.nC_0, out trailingOnes, out totalCoeff);
			
			if(totalCoeff == 0)
				return coeffLevelList;
			
			return null;
		}
		
		
		public static void getCoeffToken(BitStream bitstream, nC _nC, out UInt32 trailingOnes, out UInt32 totalCoeff)
		{
			Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenResultantMap = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
			Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC;
			switch(_nC)
			{
				case nC.nC_0 : coeffTokenMapnC = coeffTokenMapnC_0; break;
				case nC.nC_2 : coeffTokenMapnC = coeffTokenMapnC_2; break;
				case nC.nC_4 : coeffTokenMapnC = coeffTokenMapnC_4; break;
				case nC.nC_8 : coeffTokenMapnC = coeffTokenMapnC_8; break;
				case nC.nC_minus1 : coeffTokenMapnC = coeffTokenMapnC_minus1; break;
				case nC.nC_minus2 : coeffTokenMapnC = coeffTokenMapnC_minus2; break;
				default:throw new H264Impl.NET.H264ImplConformanceException(); break;
			}
			
			foreach (KeyValuePair<KeyValuePair<byte, byte>, bool[]> kvp in coeffTokenMapnC) 
				coeffTokenResultantMap.Add(kvp.Key, kvp.Value);
			
			bool readBit;
			KeyValuePair<KeyValuePair<byte, byte>, bool[]> hit = new KeyValuePair<KeyValuePair<byte, byte>, bool[]>(new KeyValuePair<byte, byte>(0, 0), new bool[1]{false});
			int i;
			for(i=0; coeffTokenResultantMap.Count != 1; i++)
			{
				readBit = bitstream.getBit();
				foreach (KeyValuePair<KeyValuePair<byte, byte>, bool[]> kvp in coeffTokenResultantMap) 
				{
					
					if(readBit != kvp.Value[i])
						coeffTokenResultantMap.Remove(kvp.Key);
					else
						hit = kvp;
					
				
				}
			}
			
			readBit = bitstream.getBit();
			if(readBit == hit.Value[i])
			{
				trailingOnes = hit.Key.Key;
				totalCoeff = hit.Key.Value;
			}
			else 
				throw new H264Impl.NET.H264ImplConformanceException();
			



		}
		
		private static UInt32 TotalCoeff(UInt32 coeff_token)
		{
			return 0;
		}
		
		private static UInt32 TrailingOnes(UInt32 coeff_token)
		{
			return 0;
		}
		
			
		public static void residual_block_cavlc( UInt32[] coeffLevel, UInt32 startIdx, UInt32 endIdx, UInt32 maxNumCoeff )
		{
			UInt32 suffixLength;
			
			for( int i = 0; i < maxNumCoeff; i++ )
				coeffLevel[ i ] = 0;
			UInt32 coeff_token = 0;
			if( TotalCoeff( coeff_token ) > 0 ) 
			{
				if( TotalCoeff( coeff_token ) > 10 && TrailingOnes( coeff_token ) < 3 )
					suffixLength = 1;
				else
					suffixLength = 0;
				
				Int32[] level = new Int32[TotalCoeff( coeff_token )];
				for( int i = 0; i < TotalCoeff( coeff_token ); i++ )
					if( i < TrailingOnes( coeff_token ) )
					{
						bool trailing_ones_sign_flag = false;
						level[ i ] = 1 - 2 * Convert.ToInt32(trailing_ones_sign_flag);
					}
					else
					{
						Int32 level_prefix = 0;
						Int32 level_suffix = 0;
						//level_prefix
						Int32 levelCode = ((Int32)(Math.Min( 15, level_prefix )) << (Int32)(suffixLength) );
					 	if( suffixLength > 0 || level_prefix >= 14 ) 
					 	{
					 		//level_suffix
					 		levelCode += level_suffix;
					 	}
					 	if( level_prefix >= 15 && suffixLength == 0 )
					 		levelCode += 15;
						if( level_prefix >=16 )
							levelCode += ( 1 << ( level_prefix - 3 ) ) - 4096;
						if( i == TrailingOnes( coeff_token ) && TrailingOnes( coeff_token ) < 3 )
							levelCode += 2;
						if( levelCode % 2 == 0 )
							level[ i ] = (Int32)( levelCode + 2 ) >> (Int32)1;
						else
							level[ i ] = (Int32)( -levelCode - 1 ) >> (Int32)1;
						if( suffixLength == 0 )
							suffixLength = 1;
						if( Math.Abs( level[ i ] ) > ( (Int16)3 << (Int16)( suffixLength - 1 ) ) && suffixLength < 6 )
							suffixLength++;
					}
					
				Int32 zerosLeft;	
				if( TotalCoeff( coeff_token ) < endIdx - startIdx + 1 ) 
				{
					Int32 total_zeros = 0;
					//total_zeros
					
					zerosLeft = total_zeros;
				}
				else
					zerosLeft = 0;
				
				Int32[] run = new Int32[TotalCoeff( coeff_token )];
				for( int i = 0; i < TotalCoeff( coeff_token ) - 1; i++ )
				{
					if( zerosLeft > 0 )
					{
						Int32 run_before = 0;
						//run_before
						run[ i ] = run_before;
					}
					else
						run[ i ] = 0;
					zerosLeft = zerosLeft - run[ i ];
				}
				run[ TotalCoeff( coeff_token ) - 1 ] = zerosLeft;
				Int32 coeffNum = -1;
				for( UInt32 i = TotalCoeff( coeff_token ) - 1; i >= 0; i-- ) 
				{
					coeffNum += run[ i ] + 1;
					coeffLevel[ startIdx + coeffNum ] = (UInt32)(level[ i ]);
				}
					
						
			}
		}
		
		public enum nC 
		{
			nC_0,
			nC_2,
			nC_4,
			nC_8,
			nC_minus1,
			nC_minus2
		}
		
		public static void createCoeffToken(UInt32 trailingOnes, UInt32 totalCoeff, nC _nC)
		{
			if(trailingOnes>3 || totalCoeff>16)
				throw new H264ImplConformanceException();
			
			Console.WriteLine("hi {0}", jaggedArray[totalCoeff][trailingOnes][(int)(_nC)][1]);
		}
		//totalCoeff->trailingOnes->nC->data
		static int[][][][]jaggedArray = new int[1][][][]
										{				
											new int[2][][]
											{
												new int[6][] 
												{
													new int[2]{1,2},
													new int[2]{1,2},	
													new int[1]{5},
													new int[3]{6, 8, 9},
													new int[3]{5, 7, 3},
													new int[4]{2, 8, 4, 7},
												},
												new int[6][]
												{
													new int[]{5, 6},
													new int[]{7, 9},
													new int[]{8},
													new int[]{4, 9, 0, 3},
													new int[]{6},
													new int[]{4, 5},
												}
											}
																
										};
			
		
		
		//nC->totalCoeff->trailingOnes->data
		static bool[][][][]jaggedArray1 = new bool[1][][][]
										{				
											new bool[2][][]
											{
												new bool[1][] 
												{
													new bool[1]{  true}
												},
												new bool[2][]
												{
													new bool[6]{  false, false, false, true,  false, true},
													new bool[2]{  false, true}
												}
											}
																
										};
		
		static bool[][][][] jaggedArray2 = new bool[6][][][]
										   {
											new bool[17][][]
											{
new bool[1][] 
{
	new bool[1]{  true}
},
new bool[2][]
{
       new bool[6]{  false, false, false, true,  false, true},
       new bool[2]{  false, true}  					
},
new bool[3][]
{
       new bool[8]{ false, false, false, false,  false, true, true, true},
       new bool[6]{ false, false, false, true,  false, false} 	,		
       new bool[3]{ false, false, true}
},
new bool[4][]
{
      new bool[9]{ false, false, false, false,  false, false, true, true,  true},
      new bool[8]{ false, false, false, false,  false, true, true, false},  			
      new bool[7]{ false, false, false, false,  true, false, true},  			
      new bool[5]{ false, false, false, true,  true}  				
},
new bool[4][]
{
      new bool[10]{ false, false, false, false,  false, false, false, true,  true, true},
      new bool[9]{ false, false, false, false,  false, false, true, true,  false},  		
      new bool[8]{ false, false, false, false,  false, true, false, true},  			
      new bool[6]{ false, false, false, false,  true, true}  			
},
new bool[4][]
{
       new bool[11]{ false, false, false, false,  false, false, false, false,  true, true, true},
       new bool[10]{ false, false, false, false,  false, false, false, true,  true, false},  		
       new bool[9]{ false, false, false, false,  false, false, true, false,  true},  		
       new bool[7]{ false, false, false, false,  true, false, false}  			
},
new bool[4][]
{
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, true,  true},
      new bool[11]{ false, false, false, false,  false, false, false, false,  true, true, false},  		
      new bool[10]{ false, false, false, false,  false, false, false, true,  false, true},  		
      new bool[8]{ false, false, false, false,  false, true, false, false}  			
},
new bool[4][]
{
	new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, true,  true},
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, true,  false},  	
      new bool[11]{ false, false, false, false,  false, false, false, false,  true, false, true},  		
      new bool[9]{ false, false, false, false,  false, false, true, false,  false}  		
},
new bool[4][]
{
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, false,  false},
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, true,  false},  	
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, false,  true},  	      
      new bool[10]{ false, false, false, false,  false, false, false, true,  false, false}
},
new bool[4][]
{
      new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, true,  true, true},
      new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, true,  true, false},  	
      new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, false,  true},  	
      new bool[11]{ false, false, false, false,  false, false, false, false,  true, false, false},  			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
},
new bool[4][]
{
       new bool[14]{  false, false, false, false,  false, false, false, false,  false, false, true, false,  true, true},
       new bool[14]{  false, false, false, false,  false, false, false, false,  false, false, true, false,  true, false},  		 
       new bool[14]{  false, false, false, false,  false, false, false, false,  false, false, true, true,  false, true}, 		 
       new bool[13]{  false, false, false, false,  false, false, false, false,  false, true, true, false,  false}, 		
},
new bool[4][]
{
       new bool[15]{  false, false, false, false,  false, false, false, false,  false, false, false, true,  true, true, true},
       new bool[15]{  false, false, false, false,  false, false, false, false,  false, false, false, true,  true, true, false}, 		 
       new bool[14]{  false, false, false, false,  false, false, false, false,  false, false, true, false,  false, true}, 		 
       new bool[14]{  false, false, false, false,  false, false, false, false,  false, false, true, true,   false, false},  		 
},
new bool[4][]
{
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   false, true, true},
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   false, true, false}, 	 	 
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   true,  false, true},  	 
       new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true,  false,  false, false},  		 
},
new bool[4][]
{
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  true, true, true},
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  false, false, true},  	 
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   false, false, true}, 		 
       new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   true,  false, false},  	 
},
new bool[4][]
{
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  false, true, true},
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  true, true, false},  	 
      new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  true, false, true},  	 
      new bool[15]{ false, false, false, false,  false, false, false, false,  false, false, false, true,   false, false, false}  	 
},
new bool[4][]
{
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  false, true, true, true},
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  false, true, false},  	 
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  false, false, true},  	 
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  true, false, false},      
},
new bool[4][]
{
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  false, true, false, false},
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  false, true, true, false},  	 
       new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  false, true, false, true}, 	 
	   new bool[16]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true,  false, false, false} 	 
}
											}, new bool[17][][]
											{

new bool[1][]
{
      new bool[2]{   	 true, true}
},
new bool[2][]
{
       new bool[6]{    false, false, true, false,  true, true},
       new bool[2]{	 true, false}  					
},
new bool[3][]
{
       new bool[6]{  	 false, false, false, true,  true, true},
       new bool[5]{ 	 false, false, true, true,  true} ,				
       new bool[3]{	 false, true, true}  				
},
new bool[4][]
{
	
       new bool[7]{	 false, false, false, false,  true, true, true},
       new bool[6]{	 false, false, true, false,  true, false},  			
       new bool[6]{	 false, false, true, false,  false, true}, 				
       new bool[4]{	 false, true, false, true}				
},
new bool[4][]
{
	       new bool[8]{ 	 false, false, false, false,  false, true, true, true},  			
       new bool[6]{	 false, false, false, true,  true, false},  			
       new bool[6]{	 false, false, false, true,  false, true},  			
       new bool[4]{	 false, true, false, false}  				
},
new bool[4][]
{
	       new bool[8]{	 false, false, false, false,  false, true, false, false},  			
       new bool[7]{	 false, false, false, false,  true, true, false}, 			
       new bool[7]{	 false, false, false, false,  true, false, true},  			
       new bool[5]{	 false, false, true, true,  false}  				
},
new bool[4][]
{
	       new bool[9]{ 	 false, false, false, false,  false, false, true, true,  true},  		
       new bool[8]{ 	 false, false, false, false,  false, true, true, false},  			
       new bool[8]{	 false, false, false, false,  false, true, false, true},  			
       new bool[6]{ 	 false, false, true, false,  false, false}  			
},
new bool[4][]
{
	       new bool[11]{	 false, false, false, false,  false, false, false, true,  true, true, true},  		
       new bool[9]{ 	 false, false, false, false,  false, false, true, true,  false}, 			
       new bool[9]{	 false, false, false, false,  false, false, true, false,  true},  		
       new bool[6]{	 false, false, false, true,  false, false}  			
},
new bool[4][]
{
	       new bool[11]{ 	 false, false, false, false,  false, false, false, true,  false, true, true},  		
       new bool[11]{	 false, false, false, false,  false, false, false, true,  true, true, false},  		
       new bool[11]{	 false, false, false, false,  false, false, false, true,  true, false, true},  		
       new bool[7]{	 false, false, false, false,  true, false, false}  			
},
new bool[4][]
{
	       new bool[12]{	 false, false, false, false,  false, false, false, false,  true, true, true, true},  		
       new bool[11]{ 	 false, false, false, false,  false, false, false, true,   false, true, false},  		
       new bool[11]{  	 false, false, false, false,  false, false, false, true,   false, false, true},  		
       new bool[9]{	 false, false, false, false,  false, false, true,  false,  false}  				                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
},
new bool[4][]
{
	         new bool[12]{     false, false, false, false,  false, false, false, false,  true, false, true, true}, 		
         new bool[12]{	 false, false, false, false,  false, false, false, false,  true, true, true, false},  		
         new bool[12]{	 false, false, false, false,  false, false, false, false,  true, true, false, true},  		
         new bool[11]{	 false, false, false, false,  false, false, false, true,   true, false, false} 			
},
new bool[4][]
{
	         new bool[12]{	 false, false, false, false,  false, false, false, false,  true, false, false, false},  		
         new bool[12]{	 false, false, false, false,  false, false, false, false,  true, false, true, false},  		
         new bool[12]{	 false, false, false, false,  false, false, false, false,  true, false, false, true},  		
         new bool[11]{	 false, false, false, false,  false, false, false, true,   false, false, false}  			
},
new bool[4][]
{
	         new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, true,  true},  		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, true,  false}, 	 	
         new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, false,  true},  		
       	 new bool[12]{ false, false, false, false,  false, false, false, false,  true,  true, false, false}  		
},
new bool[4][]
{
	       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, true,  true},  		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, true,  false},  		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, false,  true}, 		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, true, false,  false}  		
},
new bool[4][]
{
	       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, false, true, true,  true},  		
       	 new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, false,  true, true},  		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, false, true, true,  false},  		
       	 new bool[13]{ false, false, false, false,  false, false, false, false,  false, true, false, false,  false}  		
},
new bool[4][]
{
	       	 new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, false,  false, true},  		
         new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, false,  false, false},  		
        new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, true, false,  true, false},  		
         new bool[13]{ false, false, false, false,  false, false, false, false,  false, false, false, false,  true}  		
},
new bool[4][]
{
	     new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, false, true,  true, true},  		
         new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, false, true,  true, false},  		
       	 new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, false, true,  false, true},  		
      	 new bool[14]{ false, false, false, false,  false, false, false, false,  false, false, false, true,  false, false}  		
}
											},
											new bool[17][][]{	

new bool[1][]
{
         new bool[4]{		true, true, true, true} 
},
new bool[2][]
{
         new bool[6]{		false, false, true, true,  true, true},
       	 new bool[4]{	true, true, true, false}   		
},
new bool[3][]
{
      	 new bool[6]{	false, false, true, false,  true, true},
     	 new bool[5]{	false, true, true, true,  true},   		
      	 new bool[4]{	true, true, false, true}  		
},
new bool[4][]
{

      	 new bool[6]{	false, false, true, false,  false, false},   	
      	 new bool[5]{	false, true, true, false,  false},  		
      	 new bool[5]{	false, true, true, true,  false},  		
      	 new bool[4]{	true, true, false, false}   		
},
new bool[4][]
{

      	 new bool[7]{	false, false, false, true,  true, true, true},  	
      	 new bool[5]{	false, true, false, true,  false},  		
      	 new bool[5]{	false, true, false, true,  true},  		
      	 new bool[4]{	true, false, true, true}  		
},
new bool[4][]
{

      	 new bool[7]{	false, false, false, true,  false, true, true}, 	
     	 new bool[5]{	false, true, false, false,  false}, 		
     	 new bool[5]{	false, true, false, false,  true},  		
      	 new bool[4]{	true, false, true, false}   		
},
new bool[4][]
{

      	 new bool[7]{	false, false, false, true,  false, false, true}, 	
      	 new bool[6]{	false, false, true, true,  true, false}, 		
      	 new bool[6]{	false, false, true, true,  false, true},  	
       	 new bool[4]{	true, false, false, true}   		
},
new bool[4][]
{

      	 new bool[7]{	false, false, false, true,  false, false, false},  	
      	 new bool[6]{	false, false, true, false,  true, false},  	
      	 new bool[6]{	false, false, true, false,  false, true},  	
      	 new bool[4]{	true, false, false, false}   		
},
new bool[4][]
{

      	 new bool[8]{	false, false, false, false,  true, true, true, true}, 	
      	 new bool[7]{	false, false, false, true,  true, true, false}, 	
     	 new bool[7]{	false, false, false, true,  true, false, true},  	
      	 new bool[5]{	false, true, true, false,  true}   		
},
new bool[4][]
{

      	 new bool[8]{	false, false, false, false,  true, false, true, true},  	
      	 new bool[8]{	false, false, false, false,  true, true, true, false},  
       	 new bool[7]{	false, false, false, true,  false, true, false}, 	
      	 new bool[6]{	false, false, true, true,  false, false}   			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
},
new bool[4][]
{

         new bool[9]{	false, false, false, false,  false, true, true, true,  true},  		
         new bool[8]{ false, false, false, false,  true, false, true, false},  			
        new bool[8]{	false, false, false, false,  true, true, false, true},  			
         new bool[7]{	false, false, false, true,  true, false, false}   			
},
new bool[4][]
{

         new bool[9]{	false, false, false, false,  false, true, false, true,  true},  		
         new bool[9]{	false, false, false, false,  false, true, true, true,  false},  		
         new bool[8]{	false, false, false, false,  true, false, false, true},			
         new bool[8]{	false, false, false, false,  true, true, false, false}   			
},
new bool[4][]
{

       	 new bool[9]{	false, false, false, false,  false, true, false, false,  false},  		
         new bool[9]{	false, false, false, false,  false, true, false, true,  false},  		
       	 new bool[9]{	false, false, false, false,  false, true, true, false,  true},  		
       	 new bool[8]{	false, false, false, false,  true, false, false, false}   			
},
new bool[4][]
{

       	 new bool[10]{false, false, false, false,  false, false, true, true,  false, true},  		
       	 new bool[9]{	false, false, false, false,  false, false, true, true,  true},  		
       	 new bool[9]{	false, false, false, false,  false, true, false, false,  true},  	
       	 new bool[9]{	false, false, false, false,  false, true, true, false,  false}   		
},
new bool[4][]
{

       	 new bool[10]{	false, false, false, false,  false, false, true, false,  false, true}, 		
       	 new bool[10]{	false, false, false, false,  false, false, true, true,  false, false}, 
       	 new bool[10]{	false, false, false, false,  false, false, true, false,  true, true}, 	
       	 new bool[10]{	false, false, false, false,  false, false, true, false,  true, false}   		
},
new bool[4][]
{

         new bool[10]{		false, false, false, false,  false, false, false, true,  false, true},  	
       	 new bool[10]{	false, false, false, false,  false, false, true, false,  false, false},  		
       	 new bool[10]{	false, false, false, false,  false, false, false, true,  true, true}, 		
       	 new bool[10]{	false, false, false, false,  false, false, false, true,  true, false}  		
},
new bool[4][]
{

         new bool[10]{		false, false, false, false,  false, false, false, false,  false, true},  		
       	 new bool[10]{	false, false, false, false,  false, false, false, true,  false, false},  		
       	 new bool[10]{	false, false, false, false,  false, false, false, false,  true, true}, 		
         new bool[10]{		false, false, false, false,  false, false, false, false,  true, false}  	
}},
new bool[17][][]
{
											

new bool[1][]
{
       new bool[6]{  false, false, false, false,  true, true} 		
},
new bool[2][]
{

       new bool[6]{ false, false, false, false,  false, false},  	
       new bool[6]{ false, false, false, false,  false, true}  	
},
new bool[3][]
{

       new bool[6]{false, false, false, true,  false, false},
       new bool[6]{false, false, false, true,  false, true},  	
       new bool[6]{false, false, false, true,  true, false}  	
},
new bool[4][]
{

       new bool[6]{false, false, true, false,  false, false},  	
       new bool[6]{false, false, true, false,  false, true},  	
       new bool[6]{false, false, true, false,  true, false},  	
       new bool[6]{false, false, true, false,  true, true}  	
},
new bool[4][]
{

       new bool[6]{false, false, true, true,  false, false},  	
       new bool[6]{false, false, true, true,  false, true},  	
       new bool[6]{false, false, true, true,  true, false},  	
      new bool[6]{false, false, true, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{false, true, false, false,  false, false},  	
       new bool[6]{false, true, false, false,  false, true},  	
       new bool[6]{false, true, false, false,  true, false},  	
       new bool[6]{false, true, false, false,  true, true}  	
},
new bool[4][]
{

       new bool[6]{false, true, false, true,  false, false},  	
       new bool[6]{false, true, false, true,  false, true},  	
       new bool[6]{false, true, false, true,  true, false},  	
       new bool[6]{false, true, false, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{false, true, true, false,  false, false},  	
       new bool[6]{false, true, true, false,  false, true},  	
       new bool[6]{false, true, true, false,  true, false}, 		
       new bool[6]{false, true, true, false,  true, true}  	
},
new bool[4][]
{

       new bool[6]{false, true, true, true,  false, false}, 		
       new bool[6]{false, true, true, true,  false, true},  	
       new bool[6]{false, true, true, true,  true, false},  	
       new bool[6]{false, true, true, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{true, false, false, false,  false, false},  	
       new bool[6]{true, false, false, false,  false, true},  	
       new bool[6]{true, false, false, false,  true, false},  	
       new bool[6]{true, false, false, false,  true, true}  			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
},
new bool[4][]
{

       new bool[6]{true,  false, false, true,  false, false},  	
       new bool[6]{  true, false, false, true,  false, true},  	
       new bool[6]{  true, false, false, true,  true, false}, 	
       new bool[6]{  true, false, false, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{  true, false, true, false,  false, false},  	
       new bool[6]{  true, false, true, false,  false, true},  	
       new bool[6]{  true, false, true, false,  true, false},  	
       new bool[6]{  true, false, true, false,  true, true}  
},
new bool[4][]
{

       new bool[6]{ true, false, true, true,  false, false},  
       new bool[6]{ true, false, true, true,  false, true},  	
       new bool[6]{ true, false, true, true,  true, false},  
       new bool[6]{ true, false, true, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{ true, true, false, false,  false, false},  
       new bool[6]{ true, true, false, false,  false, true},  	
      new bool[6]{ true, true, false, false,  true, false},  	
       new bool[6]{ true, true, false, false,  true, true}  	
},
new bool[4][]
{

       new bool[6]{ true, true, false, true,  false, false},  	
       new bool[6]{ true, true, false, true,  false, true},  	
      new bool[6]{ true, true, false, true,  true, false},  	
       new bool[6]{ true, true, false, true,  true, true}  	
},
new bool[4][]
{

       new bool[6]{ true, true, true, false,  false, false},  	
       new bool[6]{ true, true, true, false,  false, true},  
       new bool[6]{ true, true, true, false,  true, false},  
       new bool[6]{ true, true, true, false,  true, true}  
},
new bool[4][]
{

       new bool[6]{ true, true, true, true,  false, false},  
       new bool[6]{ true, true, true, true,  false, true},
       new bool[6]{ true, true, true, true,  true, false},  	
       new bool[6]{ true, true, true, true,  true, true}  	
}
},
new bool[5][][]
{

new bool[1][]
{

      new bool[2]{  false, true}   			
},
new bool[2][]
{

       new bool[6]{ false, false, false, true,  true, true},  	
       new bool[1]{ true}   			
},
new bool[3][]
{

       new bool[6]{false, false, false, true,  false, false},  	
       new bool[6]{false, false, false, true,  true, false},  	
       new bool[3]{ false, false, true}   		
},
new bool[4][]
{

       new bool[6]{false, false, false, false,  true, true},  	
       new bool[7]{false, false, false, false,  false, true, true},  	
       new bool[7]{ false, false, false, false,  false, true, false},  	
      new bool[6]{false, false, false, true,  false, true}   	
},
new bool[4][]
{

       new bool[6]{false, false, false, false,  true, false},  	
       new bool[8]{false, false, false, false,  false, false, true, true},  	
       new bool[8]{false, false, false, false,  false, false, true, false},  	
       new bool[7]{false, false, false, false,  false, false, false}   	
}
},
new bool[9][][]
{
	  
new bool[1][]
{

         new bool[1]{  true} 
},
new bool[2][]
{

       new bool[7]{ false, false, false, true,  true, true, true}, 
       new bool[2]{ false, true} 
},
new bool[3][]
{

       new bool[7]{false, false, false, true,  true, true, false}, 
       new bool[7]{false, false, false, true,  true, false, true}, 
       new bool[3]{false, false, true} 
},
new bool[4][]
{

       new bool[9]{false, false, false, false,  false, false, true, true,  true}, 
       new bool[7]{false, false, false, true,  true, false, false}, 
       new bool[7]{false, false, false, true,  false, true, true}, 
       new bool[5]{false, false, false, false,  true} 
},
new bool[4][]
{

       new bool[9]{false, false, false, false,  false, false, true, true,  false}, 
       new bool[9]{false, false, false, false,  false, false, true, false,  true}, 
       new bool[7]{false, false, false, true,  false, true, false}, 
       new bool[6]{false, false, false, false,  false, true} 
},
new bool[4][]
{

       new bool[10]{false, false, false, false,  false, false, false, true,  true, true}, 
       new bool[10]{false, false, false, false,  false, false, false, true,  true, false}, 
       new bool[9]{false, false, false, false,  false, false, true, false,  false}, 
       new bool[7]{false, false, false, true,  false, false, true} 
},
new bool[4][]
{

       new bool[11]{false, false, false, false,  false, false, false, false,  true, true, true}, 
       new bool[11]{false, false, false, false,  false, false, false, false,  true, true, false}, 
       new bool[10]{false, false, false, false,  false, false, false, true,  false, true}, 
       new bool[7]{false, false, false, true,  false, false, false} 
},
new bool[4][]
{

       new bool[12]{false, false, false, false,  false, false, false, false,  false, true, true, true}, 
       new bool[12]{false, false, false, false,  false, false, false, false,  false, true, true, false}, 
       new bool[11]{false, false, false, false,  false, false, false, false,  true, false, true}, 
       new bool[10]{false, false, false, false,  false, false, false, true,  false, false} 
},
new bool[4][]
{

       new bool[13]{false, false, false, false,  false, false, false, false,  false, false, true, true,  true}, 
       new bool[12]{false, false, false, false,  false, false, false, false,  false, true, false, true },
       new bool[12]{false, false, false, false,  false, false, false, false,  false, true, false, false}, 
       new bool[11]{false, false, false, false,  false, false, false, false,  true, false, false} 
	
	
}}};
		
	
		
		
		
		
		
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_0 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_2 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_4 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_8 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_minus1 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();
		static Dictionary<KeyValuePair<byte, byte>, bool[]> coeffTokenMapnC_minus2 = new Dictionary<KeyValuePair<byte, byte>, bool[]>();

		static CAVLC()
		{
			Console.WriteLine("Entering static constructor of CAVLC");
			

	//nC=0 clean
//nC->totalCoeff->trailingOnes->data
		
											/*
//	nc=2 not clean

/*	//nc=4 not clean
	

	
	
	//nc=8 not clean
	
	
//	nc=-1, not clean

	
	
//nc=-2 not clean
*/		}
		
	//};
	
	
	}}




//0 0 1 					11 					1111 		0000 11		01 			1
//0 1 0001 01 			0010 11 			0011 11 	0000 00 	0001 11 	0001 111
//1 1 01 					10 					1110 		0000 01 	1 			01
//0 2 0000 0111 			0001 11 			0010 11		0001 00		0001 00 	0001 110
//1 2 0001 00 			0011 1				0111 1 		0001 01 	0001 10 	0001 101
//2 2 001 				011 				1101		0001 10 	001 		001
//0 3 0000 0011 1			0000 111 			0010 00 	0010 00 	0000 11 	0000 0011 1
//1 3 0000 0110 			0010 10 			0110 0 		0010 01 	0000 011 	0001 100
//2 3 0000 101 			0010 01				0111 0 		0010 10 	0000 010 	0001 011
//3 3 0001 1 				0101				1100 		0010 11 	0001 01 	0000 1
//0 4 0000 0001 11 		0000 0111 			0001 111 	0011 00 	0000 10 	0000 0011 0
//1 4 0000 0011 0 		0001 10 			0101 0 		0011 01 	0000 0011 	0000 0010 1
//2 4 0000 0101 			0001 01 			0101 1 		0011 10 	0000 0010 	0001 010
//3 4 0000 11 			0100 				1011		0011 11 	0000 000 	0000 01
//0 5 0000 0000 111 		0000 0100 			0001 011	0100 00 	- 			0000 0001 11
//1 5 0000 0001 10 		0000 110			0100 0		0100 01 	-			0000 0001 10
//2 5 0000 0010 1 		0000 101 			0100 1 		0100 10 	-			0000 0010 0
//3 5 0000 100 			0011 0 				1010 		0100 11 	- 			0001 001
//0 6 0000 0000 0111 1 	0000 0011 1 		0001 001	0101 00 	- 			0000 0000 111
//1 6 0000 0000 110 		0000 0110 			0011 10		0101 01 	- 			0000 0000 110
//2 6 0000 0001 01 		0000 0101 			0011 01 	0101 10 	- 			0000 0001 01
//3 6 0000 0100 			0010 00 			1001 		0101 11 	- 			0001 000
//0 7 0000 0000 0101 1 	0000 0001 111 		0001 000 	0110 00 	- 			0000 0000 0111
//1 7 0000 0000 0111 0 	0000 0011 0			0010 10 	0110 01 	- 			0000 0000 0110
//2 7 0000 0000 101 		0000 0010 1 		0010 01 	0110 10		- 			0000 0000 101
//3 7 0000 0010 0 		0001 00 			1000 		0110 11 	- 			0000 0001 00
//0 8 0000 0000 0100 0 	0000 0001 011 		0000 1111	0111 00		- 			0000 0000 0011 1
//1 8 0000 0000 0101 0 	0000 0001 110 		0001 110	0111 01 	- 			0000 0000 0101
//2 8 0000 0000 0110 1 	0000 0001 101 		0001 101 	0111 10 	- 			0000 0000 0100
//3 8 0000 0001 00 		0000 100 			0110 1 		0111 11 	- 			0000 0000 100
//0 9 0000 0000 0011 11 	0000 0000 1111 		0000 1011 	1000 00 	- 			-
//1 9 0000 0000 0011 10 	0000 0001 010 		0000 1110 	1000 01 	- 			-
//2 9 0000 0000 0100 1 	0000 0001 001 		0001 010	1000 10 	- 			-
//3 9 0000 0000 100 		0000 0010 0 		0011 00 	1000 11 	- 			-			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
//0 10 0000 0000 0010 11   	 0000 0000 1011 		0000 0111 1 		1001 00 	-	-
//1 10 0000 0000 0010 10 		 0000 0000 1110 		0000 1010 			1001 01 	-	-
//2 10 0000 0000 0011 01		 0000 0000 1101 		0000 1101 			1001 10		-	-
//3 10 0000 0000 0110 0		 0000 0001 100			0001 100 			1001 11 	- 	-
//0 11 0000 0000 0001 111		 0000 0000 1000 		0000 0101 1 		1010 00 	- 	-
//1 11 0000 0000 0001 110		 0000 0000 1010 		0000 0111 0 		1010 01 	- 	-
//2 11 0000 0000 0010 01		 0000 0000 1001 		0000 1001			1010 10 	- 	-
//3 11 0000 0000 0011 00 		 0000 0001 000 			0000 1100 			1010 11 	- 	-
//0 12 0000 0000 0001 011	     0000 0000 0111 1 		0000 0100 0 		1011 00 	- 	-
//1 12 0000 0000 0001 010	 	 0000 0000 0111 0	 	0000 0101 0 		1011 01 	- 	-
//2 12 0000 0000 0001 101 	 0000 0000 0110 1 		0000 0110 1 		1011 10 	- 	-	
//3 12 0000 0000 0010 00 		 0000 0000 1100 		0000 1000 			1011 11 	- 	-	
//0 13 0000 0000 0000 1111	 0000 0000 0101 1 		0000 0011 01 		1100 00 	- 	-
//1 13 0000 0000 0000 001 	 0000 0000 0101 0 		0000 0011 1 		1100 01 	- 	-
//2 13 0000 0000 0001 001		 0000 0000 0100 1		0000 0100 1 		1100 10 	- 	-
//3 13 0000 0000 0001 100 	 0000 0000 0110 0 		0000 0110 0 		1100 11 	- 	-
//0 14 0000 0000 0000 1011	 0000 0000 0011 1 		0000 0010 01		1101 00 	- 	-
//1 14 0000 0000 0000 1110 	 0000 0000 0010 11 		0000 0011 00 		1101 01 	- 	-
//2 14 0000 0000 0000 1101 	 0000 0000 0011 0 		0000 0010 11		1101 10 	- 	-
//3 14 0000 0000 0001 000 	 0000 0000 0100 0 		0000 0010 10 		1101 11 	- 	-
//0 15 0000 0000 0000 0111 	 0000 0000 0010 01 		0000 0001 01 		1110 00 	- 	-
//1 15 0000 0000 0000 1010 	 0000 0000 0010 00 		0000 0010 00 		1110 01 	- 	-
//2 15 0000 0000 0000 1001 	 0000 0000 0010 10 		0000 0001 11		1110 10 	- 	-
//3 15 0000 0000 0000 1100     0000 0000 0000 1 		0000 0001 10		1110 11 	- 	-
//0 16 0000 0000 0000 0100  	 0000 0000 0001 11 		0000 0000 01 		1111 00 	- 	-
//1 16 0000 0000 0000 0110 	 0000 0000 0001 10 		0000 0001 00 		1111 01 	- 	-
//2 16 0000 0000 0000 0101	 0000 0000 0001 01 		0000 0000 11		1111 10 	- 	-
//3 16 0000 0000 0000 1000	 0000 0000 0001 00 		0000 0000 10	    1111 11 	- 	-		
//	
//	
//	
//	
//	
//	
//	
//	
//	
//	nC=0
//0 0 1 					
//0 1 0001 01 			
//1 1 01 					
//0 2 0000 0111 			
//1 2 0001 00 			
//2 2 001 				
//0 3 0000 0011 1			
//1 3 0000 0110 			
//2 3 0000 101 			
//3 3 0001 1 				
//0 4 0000 0001 11 		
//1 4 0000 0011 0 		
//2 4 0000 0101 			
//3 4 0000 11 			
//0 5 0000 0000 111 		
//1 5 0000 0001 10 		
//2 5 0000 0010 1 		
//3 5 0000 100 			
//0 6 0000 0000 0111 1 	
//1 6 0000 0000 110 		
//2 6 0000 0001 01 		
//3 6 0000 0100 			
//0 7 0000 0000 0101 1 	
//1 7 0000 0000 0111 0 	
//2 7 0000 0000 101 		
//3 7 0000 0010 0 		
//0 8 0000 0000 0100 0 	
//1 8 0000 0000 0101 0 	
//2 8 0000 0000 0110 1 	
//3 8 0000 0001 00 		
//0 9 0000 0000 0011 11 	
//1 9 0000 0000 0011 10 	
//2 9 0000 0000 0100 1 	
//3 9 0000 0000 100 			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
//0 10 0000 0000 0010 11   	 
//1 10 0000 0000 0010 10 		 
//2 10 0000 0000 0011 01		 
//3 10 0000 0000 0110 0		
//0 11 0000 0000 0001 111		 
//1 11 0000 0000 0001 110		 
//2 11 0000 0000 0010 01		 
//3 11 0000 0000 0011 00 		 
//0 12 0000 0000 0001 011	     
//1 12 0000 0000 0001 010	 	 
//2 12 0000 0000 0001 101 	 
//3 12 0000 0000 0010 00 		 
//0 13 0000 0000 0000 1111	 
//1 13 0000 0000 0000 001 	 
//2 13 0000 0000 0001 001		 
//3 13 0000 0000 0001 100 	 
//0 14 0000 0000 0000 1011	 
//1 14 0000 0000 0000 1110 	 
//2 14 0000 0000 0000 1101 	 
//3 14 0000 0000 0001 000 	 
//0 15 0000 0000 0000 0111 	 
//1 15 0000 0000 0000 1010 	 
//2 15 0000 0000 0000 1001 	 
//3 15 0000 0000 0000 1100     
//0 16 0000 0000 0000 0100  	 
//1 16 0000 0000 0000 0110 	 
//2 16 0000 0000 0000 0101	 
//3 16 0000 0000 0000 1000	 
//	
//	
//	nc=2
//0 0  	 11 					
//0 1   	 0010 11 			
//1 1	 	 10 					
//0 2   	 0001 11 			
//1 2  	 0011 1				
//2 2 	 011 				
//0 3 	 0000 111 			
//1 3		 0010 10 			
//2 3 	 0010 01				
//3 3 	 0101				
//0 4  	 0000 0111 			
//1 4 	 0001 10 			
//2 4 	 0001 01 			
//3 4 	 0100 				
//0 5 	 0000 0100 			
//1 5 	 0000 110			
//2 5 	 0000 101 			
//3 5 	 0011 0 				
//0 6  	 0000 0011 1 		
//1 6  	 0000 0110 			
//2 6 	 0000 0101 			
//3 6  	 0010 00 			
//0 7 	 0000 0001 111 		
//1 7  	 0000 0011 0			
//2 7 	 0000 0010 1 		
//3 7 	 0001 00 			
//0 8  	 0000 0001 011 		
//1 8 	 0000 0001 110 		
//2 8 	 0000 0001 101 		
//3 8 	 0000 100 			
//0 9 	 0000 0000 1111 		
//1 9  	 0000 0001 010 		
//2 9   	 0000 0001 001 		
//3 9	 	 0000 0010 0 				                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
//0 10  	 0000 0000 1011 		
//1 10 	 0000 0000 1110 		
//2 10 	 0000 0000 1101 		
//3 10 	 0000 0001 100			
//0 11 	 0000 0000 1000 		
//1 11 	 0000 0000 1010 		
//2 11 	 0000 0000 1001 		
//3 11 	 0000 0001 000 			
//0 12      0000 0000 0111 1 		
//1 12 	 0000 0000 0111 0	 	
//2 12  	 0000 0000 0110 1 		
//3 12 	 0000 0000 1100 		
//0 13 	 0000 0000 0101 1 		
//1 13 	 0000 0000 0101 0 		
//2 13 	 0000 0000 0100 1		
//3 13 	 0000 0000 0110 0 		
//0 14 	 0000 0000 0011 1 		
//1 14 	 0000 0000 0010 11 		
//2 14 	 0000 0000 0011 0 		
//3 14 	 0000 0000 0100 0 		
//0 15 	 0000 0000 0010 01 		
//1 15  	 0000 0000 0010 00 		
//2 15  	 0000 0000 0010 10 		
//3 15     0000 0000 0000 1 		
//0 16  	 0000 0000 0001 11 		
//1 16  	 0000 0000 0001 10 		
//2 16 	 0000 0000 0001 01 		
//3 16 	 0000 0000 0001 00 		
//	
//	nc=4
//0 0 		1111 		
//0 1  		0011 11 	
//1 1 		1110 		
//0 2 		0010 11		
//1 2 		0111 1 		
//2 2 		1101		
//0 3 		0010 00 	
//1 3 		0110 0 		
//2 3 		0111 0 		
//3 3 		1100 		
//0 4 		0001 111 	
//1 4 		0101 0 		
//2 4 		0101 1 		
//3 4 		1011		
//0 5 		0001 011	
//1 5			0100 0		
//2 5 		0100 1 		
//3 5 		1010 		
//0 6 		0001 001	
//1 6 		0011 10		
//2 6 		0011 01 	
//3 6  		1001 		
//0 7 		0001 000 	
//1 7 		0010 10 	
//2 7 		0010 01 	
//3 7 		1000 		
//0 8 		0000 1111	
//1 8 		0001 110	
//2 8 		0001 101 	
//3 8 		0110 1 		
//0 9 		0000 1011 	
//1 9 		0000 1110 
//2 9  		0001 010	
//3 9 		0011 00 			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
//0 10 		0000 0111 1 		
//1 10  		0000 1010 			
//2 10 		0000 1101 			
//3 10 		0001 100 			
//0 11 		0000 0101 1 		
//1 11 		0000 0111 0 		
//2 11 		0000 1001			
//3 11 		0000 1100 			
//0 12 		0000 0100 0 		
//1 12  		0000 0101 0 		
//2 12 		0000 0110 1 		
//3 12 		0000 1000 			
//0 13 		0000 0011 01 		
//1 13 		0000 0011 1 		
//2 13 		0000 0100 1 	
//3 13 		0000 0110 0 		
//0 14 		0000 0010 01		
//1 14 		0000 0011 00
//2 14 		0000 0010 11	
//3 14 		0000 0010 10 		
//0 15  		0000 0001 01 	
//1 15 		0000 0010 00 		
//2 15 		0000 0001 11		
//3 15 		0000 0001 10		
//0 16  		0000 0000 01 		
//1 16 		0000 0001 00 		
//2 16 		0000 0000 11		
//3 16  		0000 0000 10	
//	
//
//	
//	
//	nc=8
//0 0 0000 11		
//0 1 0000 00 	
//1 1 0000 01 	
//0 2 0001 00		
//1 2 0001 01 	
//2 2 0001 10 	
//0 3 0010 00 	
//1 3 0010 01 	
//2 3 0010 10 	
//3 3 0010 11 	
//0 4 0011 00 	
//1 4 0011 01 	
//2 4 0011 10 	
//3 4 0011 11 	
//0 5 0100 00 	
//1 5 0100 01 	
//2 5 0100 10 	
//3 5 0100 11 	
//0 6 0101 00 	
//1 6 0101 01 	
//2 6 0101 10 	
//3 6 0101 11 	
//0 7 0110 00 	
//1 7 0110 01 	
//2 7 0110 10		
//3 7 0110 11 	
//0 8 0111 00		
//1 8 0111 01 	
//2 8 0111 10 	
//3 8 0111 11 	
//0 9 1000 00 	
//1 9 1000 01 	
//2 9 1000 10 	
//3 9 1000 11 			                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		                      		
//0 10 001 00 	
//1 10 1001 01 	
//2 10 1001 10	
//3 10 1001 11 	
//0 11 1010 00 	
//1 11 1010 01 	
//2 11 1010 10 	
//3 11 1010 11 
//0 12 1011 00 
//1 12 1011 01 	
//2 12 1011 10 
//3 12 1011 11 	
//0 13 1100 00 
//1 13 1100 01 	
//2 13 1100 10 	
//3 13 1100 11 	
//0 14 1101 00 	
//1 14 1101 01 	
//2 14 1101 10 	
//3 14 1101 11 	
//0 15 1110 00 	
//1 15 1110 01 
//2 15 1110 10 
//3 15 1110 11 
//0 16 1111 00 
//1 16 1111 01 	
//2 16 1111 10 	
//3 16 1111 11 	
//	
//	
//	nc=-1
//0 0 01 			
//0 1 0001 11 	
//1 1 1 			
//0 2 0001 00 	
//1 2 0001 10 	
//2 2 001 		
//0 3 0000 11 	
//1 3 0000 011 	
//2 3 0000 010 	
//3 3 0001 01 	
//0 4 0000 10 	
//1 4 0000 0011 	
//2 4 0000 0010 	
//3 4 0000 000 	
//
//	
//	
//nc=-2
//0 0 1
//0 1 0001 111
//1 1 01
//0 2 0001 110
//1 2 0001 101
//2 2 001
//0 3 0000 0011 1
//1 3 0001 100
//2 3 0001 011
//3 3 0000 1
//0 4 0000 0011 0
//1 4 0000 0010 1
//2 4 0001 010
//3 4 0000 01
//0 5 0000 0001 11
//1 5 0000 0001 10
//2 5 0000 0010 0
//3 5 0001 001
//0 6 0000 0000 111
//1 6 0000 0000 110
//2 6 0000 0001 01
//3 6 0001 000
//0 7 0000 0000 0111
//1 7 0000 0000 0110
//2 7 0000 0000 101
//3 7 0000 0001 00
//0 8 0000 0000 0011 1
//1 8 0000 0000 0101
//2 8 0000 0000 0100
//3 8 0000 0000 100

	
